<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="{{ url_for('static',path='/echarts.min.js') }}"></script>
</head>
<body>


<h1>这是一个ajax的测试</h1>

<div id = "echart1" style="width: 600px; height: 400px"></div>


<script>

    let values;

    function echarts1(values){
         var chart1 = echarts.init(document.querySelector('#echart1'));
        chart1.setOption({
            xAxis: {
                type: 'category',
                data: ["11",'222','222']
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                data: values,
                type: 'bar'
            }]
        });
    }

    //此时就是发起一个请求,发送到后端的接口
    fetch("/getdata",{ //相当于从本机服务器发起一个请求,所有host一致的
        // method:"post",
        // body:JSON.stringify({name:'小明'})
    }) //发起一个请求
    .then((response) => response.json())
    .then((data) => {
          //此时绘图
          echarts1(data)
  });



</script>
</body>
</html>